package cn.iocoder.yudao.module.handguard.controller.app.matchinginfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.handguard.controller.app.matchinginfo.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.matchinginfo.MatchingInfoDO;
import cn.iocoder.yudao.module.handguard.convert.matchinginfo.MatchingInfoConvert;
import cn.iocoder.yudao.module.handguard.service.matchinginfo.MatchingInfoService;

@Tag(name = "小程序 - 产品类型-补充资料内容-匹配")
@RestController
@RequestMapping("/hutai/matching-info")
@Validated
public class MatchingInfoController {

    @Resource
    private MatchingInfoService matchingInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建产品类型-补充资料内容-匹配")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:create')")
    public CommonResult<Long> createMatchingInfo(@Valid @RequestBody MatchingInfoCreateReqVO createReqVO) {
        return success(matchingInfoService.createMatchingInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新产品类型-补充资料内容-匹配")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:update')")
    public CommonResult<Boolean> updateMatchingInfo(@Valid @RequestBody MatchingInfoUpdateReqVO updateReqVO) {
        matchingInfoService.updateMatchingInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除产品类型-补充资料内容-匹配")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:delete')")
    public CommonResult<Boolean> deleteMatchingInfo(@RequestParam("id") Long id) {
        matchingInfoService.deleteMatchingInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得产品类型-补充资料内容-匹配")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:query')")
    public CommonResult<MatchingInfoRespVO> getMatchingInfo(@RequestParam("id") Long id) {
        MatchingInfoDO matchingInfo = matchingInfoService.getMatchingInfo(id);
        return success(MatchingInfoConvert.INSTANCE.convert(matchingInfo));
    }

    @GetMapping("/list")
    @Operation(summary = "获得产品类型-补充资料内容-匹配列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:query')")
    public CommonResult<List<MatchingInfoRespVO>> getMatchingInfoList(@RequestParam("ids") Collection<Long> ids) {
        List<MatchingInfoDO> list = matchingInfoService.getMatchingInfoList(ids);
        return success(MatchingInfoConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得产品类型-补充资料内容-匹配分页")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:query')")
    public CommonResult<PageResult<MatchingInfoRespVO>> getMatchingInfoPage(@Valid MatchingInfoPageReqVO pageVO) {
        PageResult<MatchingInfoDO> pageResult = matchingInfoService.getMatchingInfoPage(pageVO);
        return success(MatchingInfoConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出产品类型-补充资料内容-匹配 Excel")
    @PreAuthorize("@ss.hasPermission('hutai:matching-info:export')")
    @OperateLog(type = EXPORT)
    public void exportMatchingInfoExcel(@Valid MatchingInfoExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<MatchingInfoDO> list = matchingInfoService.getMatchingInfoList(exportReqVO);
        // 导出 Excel
        List<MatchingInfoExcelVO> datas = MatchingInfoConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "产品类型-补充资料内容-匹配.xls", "数据", MatchingInfoExcelVO.class, datas);
    }

}
